/**
 @file ctc_usw_flexe_cli.c

 @author  Copyright (C) 2011 Centec Networks Inc.  All rights reserved.

 @date 2009-11-14

 @version v2.0

 The file apply clis of port module
*/

#include "ctc_api.h"
#include "ctcs_api.h"
#include "ctc_cli.h"
#include "ctc_cli_common.h"
#include "ctc_debug.h"
#include "ctc_flexe_cli.h"

extern int32
sys_usw_flexe_debug_show_ins_sch(uint8 lchip, uint8 flexe_shim_id, uint8 inst_id, uint8 dir);
extern int32
sys_usw_flexe_debug_show_inst_status(uint8 lchip, uint8 flexe_shim_id);
extern int32
sys_usw_flexe_debug_show_inst_ohram(uint8 lchip, uint8 flexe_shim_id, uint8 inst_id, uint8 dir);
extern int32
sys_usw_flexe_debug_show_client(uint8 lchip, uint32 client_id);
extern int32
sys_usw_flexe_debug_show_group(uint8 lchip, uint32 group_id);
extern int32 
sys_usw_flexe_debug_show_status(uint8 lchip);
extern int32 
sys_usw_flexe_debug_show_alarm(uint8 lchip);



CTC_CLI(ctc_cli_show_flexe_status,
        ctc_cli_show_flexe_status_cmd,
        "show flexe status",
        "Show operate",
        CTC_CLI_FLEXE_M_STR,
        "Status")
{
    int32 ret = 0;

    ret = sys_usw_flexe_debug_show_status(g_api_lchip);
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s \n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }
    
    return ret;
}

CTC_CLI(ctc_cli_show_flexe_group_detail,
        ctc_cli_show_flexe_group_detail_cmd,
        "show flexe group GROUP_ID detail",
        "Show operate",
        CTC_CLI_FLEXE_M_STR,
        "FlexE group",
        "group id",
        "Detailed information"
        )
{
    int32 ret = 0;
    uint32 group_id = 0;
    
    CTC_CLI_GET_UINT32("group_id", group_id, argv[0]);

    ret = sys_usw_flexe_debug_show_group(g_api_lchip, group_id);
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s \n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return ret;
}

CTC_CLI(ctc_cli_show_flexe_client_detail,
        ctc_cli_show_flexe_client_detail_cmd,
        "show flexe client CLIENT_ID detail",
        "Show operate",
        CTC_CLI_FLEXE_M_STR,
        "Client",
        "Client ID",
        "Detailed information")
{
    int32 ret = 0;
    uint32 client_id = 0;

    CTC_CLI_GET_UINT32_RANGE("client", client_id, argv[0], 0, CTC_MAX_UINT32_VALUE);
    
    ret = sys_usw_flexe_debug_show_client(g_api_lchip, client_id);
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s \n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }
    
    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_show_flexe_inst_sch,
        ctc_cli_show_flexe_inst_sch_cmd,
        "show flexe shim FLEXE_SHIM_ID instance INST_ID schedule (tx|rx)",
        "Show operate",
        CTC_CLI_FLEXE_M_STR,
        "FlexE Shim",
        "FlexE Shim ID",
        "Instance",
        "Instance ID",
        "Schedule",
        "TX",
        "RX")
{
    int32 ret = 0;
    uint8 flexe_shim_id = 0;
    uint8 instance_id = 0;
    uint8 dir = 0;

    CTC_CLI_GET_UINT8_RANGE("FlexE shim", flexe_shim_id, argv[0], 0, CTC_MAX_UINT8_VALUE);
    CTC_CLI_GET_UINT8_RANGE("instance", instance_id, argv[1], 0, CTC_MAX_UINT8_VALUE);

    if (0 == sal_memcmp("tx", argv[2], 2))
    {
        dir = 1;
    }

    ret = sys_usw_flexe_debug_show_ins_sch(g_api_lchip, flexe_shim_id, instance_id, dir);
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s \n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_show_flexe_inst_sta,
        ctc_cli_show_flexe_inst_sta_cmd,
        "show flexe shim FLEXE_SHIM_ID instance status ",
        "Show operate",
        CTC_CLI_FLEXE_M_STR,
        "FlexE Shim",
        "FlexE Shim ID",
        "all FlexE instances",
        "Status")
{
    int32  ret = CLI_SUCCESS;
    uint8 flexe_shim_id = 0;

    CTC_CLI_GET_UINT8_RANGE("FlexE shim", flexe_shim_id, argv[0], 0, CTC_MAX_UINT8_VALUE);

    ret = sys_usw_flexe_debug_show_inst_status(g_api_lchip, flexe_shim_id);
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s \n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }
    
    return ret;
}

CTC_CLI(ctc_cli_show_flexe_inst_ohram,
        ctc_cli_show_flexe_inst_ohram_cmd,
        "show flexe shim FLEXE_SHIM_ID instance INST_ID ohram (tx|rx)",
        "Show operate",
        CTC_CLI_FLEXE_M_STR,
        "FlexE Shim",
        "FlexE Shim ID",
        "Instance",
        "Instance ID",
        "Overhead Ram",
        "Transmit",
        "Receive")
{
    int32 ret = 0;
    uint8 flexe_shim_id = 0;
    uint8 instance_id = 0;
    uint8 dir = 0;

    CTC_CLI_GET_UINT8_RANGE("FlexE shim", flexe_shim_id, argv[0], 0, CTC_MAX_UINT8_VALUE);
    CTC_CLI_GET_UINT8_RANGE("instance", instance_id, argv[1], 0, CTC_MAX_UINT8_VALUE);

    if (0 == sal_memcmp("tx", argv[2], 2))
    {
        dir = 1;
    }

    ret = sys_usw_flexe_debug_show_inst_ohram(g_api_lchip, flexe_shim_id, instance_id, dir);

    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s \n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }
    
    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_show_flexe_alarm,
        ctc_cli_show_flexe_alarm_cmd,
        "show flexe alarm",
        "Show operate",
        CTC_CLI_FLEXE_M_STR,
        "Status")
{
    int32 ret = 0;

    ret = sys_usw_flexe_debug_show_alarm(g_api_lchip);
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s \n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }
    
    return ret;
}

int32
ctc_usw_flexe_cli_init(void)
{
    /* FlexE Debug CLI */
    install_element(CTC_SDK_MODE, &ctc_cli_show_flexe_group_detail_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_show_flexe_client_detail_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_show_flexe_inst_sch_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_show_flexe_inst_sta_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_show_flexe_inst_ohram_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_show_flexe_status_cmd);
    install_element(CTC_SDK_MODE, &ctc_cli_show_flexe_alarm_cmd);

    return CLI_SUCCESS;
}

int32
ctc_usw_flexe_cli_deinit(void)
{
    /* FlexE Debug CLI */
    uninstall_element(CTC_SDK_MODE, &ctc_cli_show_flexe_group_detail_cmd);
    uninstall_element(CTC_SDK_MODE, &ctc_cli_show_flexe_client_detail_cmd);
    uninstall_element(CTC_SDK_MODE, &ctc_cli_show_flexe_inst_sch_cmd);
    uninstall_element(CTC_SDK_MODE, &ctc_cli_show_flexe_inst_sta_cmd);
    uninstall_element(CTC_SDK_MODE, &ctc_cli_show_flexe_inst_ohram_cmd);
    uninstall_element(CTC_SDK_MODE, &ctc_cli_show_flexe_status_cmd);
    uninstall_element(CTC_SDK_MODE, &ctc_cli_show_flexe_alarm_cmd);

    return CLI_SUCCESS;
}



